package org.liuqm.servlet;

import org.liuqm.common.AjaxResult;
import org.liuqm.filter.RequestMapping;
import org.liuqm.filter.RequestParam;
import org.liuqm.pojo.Auction;
import org.liuqm.service.IAuctionService;
import org.liuqm.service.impl.AuctionServiceImpl;

/**
 * 拍卖品处理器
 */
@RequestMapping("/auction")
public class AuctionController {


    IAuctionService auctionService=new AuctionServiceImpl();

    /**
     * 添加拍卖品
     * @return
     */
    @RequestMapping("/add")
    public AjaxResult  addAuction(@RequestParam(name = "auction") Auction auction){
        System.out.println("addAuction"+auction);
        if(auctionService.addAuction(auction)>0){
            return AjaxResult.success("");
        }else{
            return AjaxResult.error("");
        }

    }
    /**
     * 修改拍卖品
     * @return
     */
    @RequestMapping("/update")
    public AjaxResult  updateAuction(@RequestParam(name = "auction") Auction auction){
        if(auctionService.updateAuction(auction)>0){
            return AjaxResult.success("");
        }else{
            return AjaxResult.error("");
        }
    }
    /**
     * 删除拍卖品
     * @return
     */
    @RequestMapping("/del")
    public AjaxResult  delAuction(@RequestParam(name = "id")  Integer id){
        System.out.println(id);
        if(auctionService.deleteAuction(id)>0){
            return AjaxResult.success("");
        }else{
            return AjaxResult.error("");
        }
    }


    /**
     * 删除拍卖品
     * @return
     */
    @RequestMapping("/getAuctionById")
    public AjaxResult  getAuctionById(@RequestParam(name = "auctionId")  Integer id){
        System.out.println(id);
        Auction auction=auctionService.getAuctionById(id);
        if(auction!=null){
            return AjaxResult.success("",auction);
        }else{
            return AjaxResult.error("");
        }
    }
    /**
     * 获取拍卖品列表
     * @return
     */
    @RequestMapping("/list")
    public AjaxResult  getAuctionList(@RequestParam(name = "auction") Auction auction){
        System.out.println("进入getAuctionList方法"+auction);
        AjaxResult result=AjaxResult.success("");
        result.setData(auctionService.getAuctions(auction));
        return result;
    }
 }
